<template>
	<div class="app-container">


		<!-- 查询参数 -->

		<div class="search-wrapper">
			<el-form class="search-param" ref="pageParam" :model="pageParam" label-width="100px" size="mini">
				<el-form-item label="类型">
					<el-input v-model="pageParam.batType" clearable></el-input>
				</el-form-item>
				<el-form-item style="margin-left: -60px;">
					<el-button type="primary" size="mini" class="el-icon-search" @click="pageByParam">确认查询</el-button>
				</el-form-item>
			</el-form>
		</div>
		<!-- 数据表格 -->
		<vxe-toolbar ref="xToolbar1" custom>
			<template #buttons>
				<vxe-button v-if="auto.btnauto(2201)" type="success" size="mini" class="el-icon-circle-plus-outline" @click="addEditClick({})">新增</vxe-button>
			</template>
		</vxe-toolbar>
		<vxe-table show-overflow :column-config="{resizable: true}" height="400" :loading="loading"
			:data="tableData.list" size="mini" border stripe>
			<vxe-column type="checkbox" width="60"></vxe-column>
			<vxe-column type="seq" title="序号" width="60"></vxe-column>
			<vxe-column field="id" title="ID"></vxe-column>
			<vxe-column field="batType" title="类型"></vxe-column>
			<!-- <vxe-column field="createTime" title="创建时间"></vxe-column>
			<vxe-column field="createUserId" title="创建人"></vxe-column>
			<vxe-column field="editTime" title="修改时间"></vxe-column>
			<vxe-column field="editUserId" title="修改人"></vxe-column>
			<vxe-column field="operationDepartment" title="运营部门"></vxe-column>
			<vxe-column field="pd" title="生产日期"></vxe-column>
			<vxe-column field="sd" title="销售日期"></vxe-column> -->
			<vxe-column title="操作" width="130" show-overflow>
				<template #default="{ row }">
					<vxe-button status="primary" v-if="auto.btnauto(2202)" icon="el-icon-edit" @click="addEditClick(row)"></vxe-button>
					<vxe-button status="success" v-if="auto.btnauto(2203)" icon="el-icon-delete" @click="handleDelete(row.id)"></vxe-button>
				</template>
			</vxe-column>
			<!-- <vxe-column field="_X_ID" title="_X_ID"></vxe-column> -->
		</vxe-table>
		<vxe-pager background size="small" stripe :loading="loading" :current-page="pageParam.pageNo"
			:page-size="pageParam.pageSize" :total="tableData.totalRow"
			:page-sizes="[10, 20, 100, {label: '大量数据', value: 1000}, {label: '全量数据', value: -1}]"
			:layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
			@size-change="handleSizeChange" background class="page-wrapper" @current-change="handleCurrentChange">
		</vxe-pager>
		<!-- 新增与编辑 -->
		<add-edit ref="addEdit" @oldlist="oldlist"></add-edit>
	</div>
</template>

<script>
	import request from '@/utils/request'
	import miniRedius from '@/shop/common/mini_radius.vue';
	import addEdit from './add_edit.vue'
	import {
		list,
		del
	} from './index.js'
	export default {
		components: {
			miniRedius,
			addEdit
		},
		data() {
			return {
				loading: true,
				timer: [],
				pageParam: {
					batType: '', //类型
					pageNo: 1,
					pageSize: 10,
				},
				tableData: {
					totalRow: 0,
					list: []
				}
			}
		},
		created() {
			this.oldlist();
		},
		methods: {
			pageByParam() {
				this.pageParam.pageNo = 1;
				this.pageParam.pageSize = 10;
				this.oldlist()
			},
			handleSizeChange(val) {
				this.pageParam.pageNo = 1;
				this.pageParam.pageSize = val;
				this.oldlist();
			},
			handleCurrentChange(val) {
				this.pageParam.pageNo = val;
				this.oldlist();
			},
			async oldlist() {
				this.loading = true;
				if (this.timer != null && this.timer.length > 0) {
					this.pageParam.stime = this.timer[0]
					this.pageParam.etime = this.timer[1]
				} else {
					this.pageParam.stime = null;
					this.pageParam.etime = null;
				}
				let result = await list(this.pageParam);
				//console.log("返回结果", result.data);
				this.loading = false;
				this.tableData.totalRow = result.total;
				this.tableData.list = result.data;

			},
			addEditClick(item) {
				this.$refs.addEdit.open(item);
			},
			// 删除
			handleDelete(id) {
				this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.del(id);
				})
			},
			async del(id) {

				let result = await del({
					id,
					token: this.pageParam.token
				});
				if (result.code == 1) {
					this.msgSuccess("删除成功");
					this.oldlist();
				}
				console.log(result)
			}
		}
	}
</script>

<style>
</style>
